﻿using EOL;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using BPO;
namespace PlotBookingRegistration
{
    public partial class Printing : Form
    {
        public Printing()
        {
            InitializeComponent();
            cboType.SelectedIndex = 2;
        }

        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Hide();
            new HOME().Show();
        }

        private void printingToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Hide();
            new Registration().ShowDialog();
        }

        private void btnSearch_Click(object sender, EventArgs e)
        {
            try
            {
                grdSearchResult.DataSource = new object[] { };
                SType type = (SType)Enum.Parse(typeof(SType), cboType.Text, true);
                switch (type)
                {
                    case SType.Agent:
                        SearchAgent();
                        break;
                    case SType.Customer:
                        SearchCustomer();
                        break;
                    case SType.Employee:
                        SearchEmployee();
                        break;
                    default:
                        break;
                }
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message);
            }
        }

        private void SearchEmployee()
        {
            bsEmployee.DataSource = BusinessRules.GetEmployeeData(txtName.Text, dtpregDate.Value);
            grdSearchResult.DataSource = bsEmployee;
            AddPrintEmpColumns();

        }

        private void AddPrintEmpColumns()
        {
            DataGridViewButtonColumn col = new DataGridViewButtonColumn();
            col.HeaderText = "Print";
            col.Text = "Print";
            col.Name = "PrintEmp";
            col.UseColumnTextForButtonValue = true;
            if (!grdSearchResult.Columns.Contains(col.Name))
                grdSearchResult.Columns.Insert(0,col);

        }

        private void SearchCustomer()
        {
            bsCustomer.DataSource = BusinessRules.GetCustomerData(txtName.Text, dtpregDate.Value);
            grdSearchResult.DataSource = bsCustomer;
            AddPrintEmpColumns();
        }

        private void SearchAgent()
        {
            bsAgent.DataSource = BusinessRules.GetAgentData(txtName.Text, dtpregDate.Value);
            grdSearchResult.DataSource = bsAgent;
            AddPrintEmpColumns();
        }

        private void grdSearchResult_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
        {
            if (e.ColumnIndex > -1)
            {
                grdSearchResult.Columns[e.ColumnIndex].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
                e.CellStyle.ForeColor = Color.Black;

            }
        }

        private void grdSearchResult_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                if (e.GetType().FullName == typeof(DataGridViewButtonCell).FullName)
                {

                }
   if (grdSearchResult.CurrentCell.ColumnIndex==0)
                {
                    if (grdSearchResult.CurrentCell != null && grdSearchResult.CurrentCell.Value != null)
                        MessageBox.Show(grdSearchResult.CurrentCell.Value.ToString());
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    }
    public enum SType
    {
        Agent,
        Customer,
        Employee
    }
}
